<template>
  <view class="normal-login-container">

    <view class="item-wrap" style="margin-bottom: 0">
      <view class="lineBottom10">
        <uni-section title="车辆信息" type="line"/>
      </view>

      <view style="margin: 8rpx 20rpx 8rpx 20rpx">
        <uni-forms labelWidth="auto">
			<!-- <uni-forms-item label="车牌号:">
			  <text  >{{ ruleForm.carBasicVo.carNo }}</text>
			</uni-forms-item> -->
			  <uni-forms-item label="车架号:">
				<text >{{ isNoEmpty(ruleForm.carBasicVo.vinNo) }}</text>
			  </uni-forms-item>

			  <uni-forms-item label="登记证日期:">
				<text >{{ isNoEmpty(ruleForm.carBasicVo.registerTime)  }}</text>
			  </uni-forms-item>

			  <uni-forms-item label="发动机号码:">
				<text >{{ isNoEmpty(ruleForm.carBasicVo.engineNo)  }}</text>
			  </uni-forms-item>

			  <uni-forms-item label="车辆归属:">
				<text >{{ isNoEmpty(ruleForm.carBasicVo.ascription)  }}</text>
			  </uni-forms-item>

			  <uni-forms-item label="车辆大区:">
				<text >{{ isNoEmpty(ruleForm.carBasicVo.region) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="车辆运营:">
			  				<text >{{ isNoEmpty(ruleForm.carBasicVo.operationsName) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="上牌城市:">
			  				<text >{{ isNoEmpty(ruleForm.carBasicVo.propertyRightName) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="车辆性质:">
			  				<text v-if="ruleForm.carBasicVo.carNature==1">营运</text>
							<text v-else>非营运</text>
			  </uni-forms-item>
			  <uni-forms-item label="车辆类型:">
			  				<text >{{ isNoEmpty(ruleForm.carBasicVo.carType) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="车辆种类:">
			  				<text >{{ isNoEmpty(ruleForm.carBasicVo.vehicleCategory) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="车辆级别:">
			  				<text >{{ isNoEmpty(ruleForm.carBasicVo.carLevel) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="车辆品牌:">
			  				<text >{{ isNoEmpty(ruleForm.carBasicVo.brandName) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="车型:">
			  				<text >{{ isNoEmpty(ruleForm.carBasicVo.modelName) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="车系:">
			  				<text >{{ isNoEmpty(ruleForm.carBasicVo.seriesName) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="燃油类型:">
				  <!-- <text >{{ ruleForm.carBasicVo.fuelType }}</text> -->
				  <text v-if="ruleForm.carBasicVo">{{ handleLabel(dict.type.fuel_type, ruleForm.carBasicVo.fuelType) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="排量:">
			  				<text >{{ isNoEmpty(ruleForm.carBasicVo.liter) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="环保标准:">
			  				<text >{{ isNoEmpty(ruleForm.carBasicVo.environmentalStandards) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="外观颜色:">
			  				<text >{{ isNoEmpty(ruleForm.carBasicVo.exteriorColor) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="内饰颜色:">
			  				<text >{{ isNoEmpty(ruleForm.carBasicVo.interiorColor) }}</text>
			  </uni-forms-item>  
			  <uni-forms-item label="座位数:">
			  				<text >{{ isNoEmpty(ruleForm.carBasicVo.seatNum) }}</text>
			  </uni-forms-item>
			  <!-- <uni-forms-item label="年检到期日:">
			  				<text >{{ isNoEmpty(ruleForm.carBasicVo.inspectionNextTime) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="年检线上线下:">
				  <text v-if="ruleForm.carBasicVo.onlineOffline==1">线上</text>
				  <text v-else>线下</text>
			  </uni-forms-item> -->
			  <uni-forms-item label="过户日期:">
			  				<text >{{ isNoEmpty(ruleForm.carBasicVo.transferDate) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="是否安装GPS:">
			  				<text v-if="ruleForm.gpsDetailVo.isInstallation==1">否</text>
			  				<text v-else-if="ruleForm.gpsDetailVo.isInstallation==0">是</text>
			  </uni-forms-item>
			  <uni-forms-item label="GPS品牌:">
				<text >{{ isNoEmpty(ruleForm.gpsDetailVo.gpsBrand) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="GPS设备类型:" v-if="ruleForm.carInStorage.purchaseSource!=='4'">
			  				<text >{{ isNoEmpty(ruleForm.gpsDetailVo.gpsType) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="GPS设备状态:" v-if="ruleForm.carInStorage.purchaseSource!=='4'">
			  				<text >{{ isNoEmpty(ruleForm.gpsDetailVo.gpsState) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="GPS开始时间:" v-if="ruleForm.carInStorage.purchaseSource!=='4'">
			  				<text >{{ isNoEmpty(ruleForm.gpsDetailVo.installTime) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="GPS结束时间:" v-if="ruleForm.carInStorage.purchaseSource!=='4'">
			  				<text >{{ ruleForm.gpsDetailVo.expireTime?ruleForm.gpsDetailVo.expireTime:'--' }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="投保渠道:">
			  				<text >{{ isNoEmpty(ruleForm.insuranceStorageDetailVo.insuranceChannels) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="商业险保险公司名称:">
			  				<text >{{ isNoEmpty(ruleForm.insuranceStorageDetailVo.syxCompany) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="商业险保险金额:">
			  				<text >{{ isNoEmpty(ruleForm.insuranceStorageDetailVo.syxAmount) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="商业险时效:">
			  				<text >{{ isNoEmpty(ruleForm.insuranceStorageDetailVo.syxValidity) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="交强险保险公司名称:">
			  				<text >{{ isNoEmpty(ruleForm.insuranceStorageDetailVo.jqxCompany) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="交强险保险金额:">
			  				<text >{{ isNoEmpty(ruleForm.insuranceStorageDetailVo.jqxAmount) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="交强险时效:">
			  				<text >{{ isNoEmpty(ruleForm.insuranceStorageDetailVo.jqxValidity) }}</text>
			  </uni-forms-item>
			  <uni-forms-item label="购车发票:" v-if="ruleForm.carInStorage.purchaseSource!=='4'">
				  	<image-common :disabled="!boole" :up-type="2" v-model="ruleForm.carBasicVo.buyCarInvoiceOss"/>
			  </uni-forms-item>
			  <uni-forms-item label="购置税发票:"v-if="ruleForm.carInStorage.purchaseSource!=='4'">
				  	<image-common :disabled="!boole" :up-type="2" v-model="ruleForm.carBasicVo.paidTaxesInvoiceOss"/>

			  </uni-forms-item>
			  <uni-forms-item label="交强险保单:">
					  <image-common :disabled="!boole" :up-type="2" v-model="ruleForm.insuranceStorageDetailVo.jqxPolicyCode"/>
			  </uni-forms-item>
			  <uni-forms-item label="商业险保单:">
				  <image-common :disabled="!boole" :up-type="2" v-model="ruleForm.insuranceStorageDetailVo.syxPolicyCode"/>
			  </uni-forms-item>
			  <uni-forms-item label="GPS免安装证明:" v-if="ruleForm.carInStorage.purchaseSource!=='4'">
				  <image-common :disabled="!boole" :up-type="2" v-model="ruleForm.gpsDetailVo.gpsProve"/>
			  </uni-forms-item>
			  
        </uni-forms>
      </view>
    </view>
  </view>
</template>

<script>
	import {
	  getPurchaseQualifiedCard, carGpsInstall, getQuotaProductByOrderCar, carGpsMonitoring, carPrchaseTax, carInspection, carInsurance, carInspectionNextTime
	} from "@/api/storage/in.js";
	var moment = require('@/utils/moment.js');
export default {
  name: 'carInfo',//基础信息
  dicts: ['fuel_type', 'car_business_type'],
  props: {
   value: {
     type: Object,
     default: {}
   }
  },
 computed: {
   ruleForm: {
     get() {
       let that = this
       const proxy = new Proxy(that.value, {
         get(target, key) {
           return Reflect.get(target, key)
         },
         set(target, key, value) {
           that.$emit('input', {...target, [key]: value})
           return true
         }
       })
       return proxy
     }
   },
   handleLabel() {
     return function (arr, type) {
       let name = ''
       arr.map((v) => {
         if (type == v.value) {
           name = v.label;
         }
       });
       return name
     }
   }
 },
  data() {
    return {};
  },
  watch:{
	  'ruleForm.insuranceStorageDetailVo':{
		  deep:true,
		  handler(val){
			  this.ruleForm.insuranceStorageDetailVo = val
		  },
		  immediate:true
	  },
	  'ruleForm.gpsDetailVo':{
	  		  deep:true,
	  		  handler(val){
	  			  this.ruleForm.gpsDetailVo = val
	  		  },
	  		  immediate:true
	  },
	  'ruleForm.carBasicVo':{
	  		  deep:true,
	  		  handler(val){
	  			  this.ruleForm.carBasicVo = val
	  		  },
	  		  immediate:true
	  },
	  'ruleForm.carInStorage':{
	  		  deep:true,
	  		  handler(val){
	  			  this.ruleForm.carInStorage = val
	  		  },
	  		  immediate:true
	  },
  },
  created() {
		this.detailInfo()
  },
  mounted() {
  },
  methods: {
	  getQualifiedCard(purchaseNo,vinNo){
	          if (this.Empty(purchaseNo) || this.Empty(vinNo)) return;
	          getPurchaseQualifiedCard(purchaseNo, vinNo).then(res => {
	            var pd = res.data;
	            if (!pd) {
	              pd = {};
	            }
	          }).finally(() => {
	            this.loading = false
	          })
	        },
	        getCarGpsInfo(carId){
	          if (this.Empty(carId)) return;
	          carGpsInstall(carId).then(res => {
	            var d = res.data;
	            if (!d) {
	              d = {};
	            }
	            this.ruleForm.gpsDetailVo.gpsType = {'1':'有线','2':'无线','3':'有线+无线'}[new String(d.equipmentType).trim()];
	            var year = d.gpsServicePeriod?.match(/\d*/)[0]
	            this.ruleForm.gpsDetailVo.installTime = d.installTime;
	            const endTime = d.installTime?moment(d.installTime).add(year^0, 'years').format("YYYY-MM-DD HH:mm:ss"):null;
				this.$set(this.ruleForm.gpsDetailVo,'expireTime',endTime)
				
	          }).finally(() => {
	            this.loading = false
	          })
	        },
	        getQuota(orderCode, carModelName){
	          if (this.Empty(orderCode)) return;
	          if (this.Empty(carModelName)) return;
	          getQuotaProductByOrderCar(orderCode, carModelName).then(res => {
	            var pd = res.data;
	            if (!pd) {
	              pd = {};
	            }
	            if (!pd['plan']) {
	              pd['plan'] = {};
	            }
	            this.ruleForm.insuranceStorageDetailVo.syxAmount = pd.insuranceCommercialCurrentAmount;
	            this.ruleForm.insuranceStorageDetailVo.jqxAmount = pd.insuranceCompulsoryCurrentAmount;
	          }).finally(() => {
	            this.loading = false
	          })
	        },
	        getCarGpsMonitoring(carId){
	          if (this.Empty(carId)) return;
	          carGpsMonitoring(carId).then(res => {
	            var d = res.data;
	            if (!d) {
	              d = {};
	            }
	            this.ruleForm.gpsDetailVo.gpsState = d?.gpsState;
	          }).finally(() => {
	            this.loading = false
	          })
	        },
	        getCarPrchaseTax(carId){
	          if (this.Empty(carId)) return;
	          carPrchaseTax(carId).then(res => {
	            var d = res.data;
	            if (!d) {
	              d = {};
	            }
	            this.ruleForm.carBasicVo.paidTaxesInvoiceOss = d.invoiceUrl;
	          }).finally(() => {
	            this.loading = false
	          })
	        },
	        getCarInspection(carId){
	          if (this.Empty(carId)) return;
	          carInspection(carId).then(res => {
	            var d = res.data;
	            if (!d) {
	              d = {};
	            }
	            this.ruleForm.carBasicVo.inspectionNextTime = d.inspectionNextTime;
	          }).finally(() => {
	            this.loading = false
	          })
	        },
	        getCarInspectionNextTime(carId){
	          if (this.Empty(carId)) return;
	          carInspectionNextTime(carId).then(res => {
	            var d = res.data;
	            this.ruleForm.carBasicVo.inspectionNextTime = d;
	          }).finally(() => {
	            this.loading = false
	          })
	        },
	        getCarInsurance(carId){
	          if (this.Empty(carId)) return;
	          //1交强险
	          carInsurance(carId, 1).then(res => {
	            var d = res.data;
	            if (!d) {
	              return
	            }
	            this.ruleForm.insuranceStorageDetailVo.jqxCompany = d.insuranceCompany;
	            this.ruleForm.insuranceStorageDetailVo.jqxValidity = d?d.actualBeginTime + '-' + d.actualEndTime:'--'
	            if (d.insuranceChannels) {
	              this.ruleForm.insuranceStorageDetailVo.insuranceChannels = {'1':'我司购买','2':'店端投保','3':'客户自购'}[new String(d.insuranceChannels).trim()];
	            }
	            this.ruleForm.insuranceStorageDetailVo.jqxAmount = d.insuranceAmount;
	          }).finally(() => {
	            this.loading = false
	          })
	          //2商业险
	          carInsurance(carId, 2).then(res => {
	            var d = res.data;
	            if (!d) {
	              return
	            }
	            this.ruleForm.insuranceStorageDetailVo.syxCompany = d.insuranceCompany;
	            this.ruleForm.insuranceStorageDetailVo.syxValidity = d?d.actualBeginTime + '-' + d.actualEndTime:'--'
	            if (d.insuranceChannels) {
	              this.ruleForm.insuranceStorageDetailVo.insuranceChannels = {'1':'我司购买','2':'店端投保','3':'客户自购'}[new String(d.insuranceChannels).trim()];
	            }
	            this.ruleForm.insuranceStorageDetailVo.syxAmount = d.insuranceAmount;
	          }).finally(() => {
	            this.loading = false
	          })
	        },
	        detailInfo(){
	          var _this = this;
	          if (this.ruleForm != null && this.ruleForm.carInStorage != null) {
	            // 自主采购的接口
	              // this.getQualifiedCard(this.ruleForm.carInStorage.purchaseNo, this.ruleForm.carBasicVo.vinNo);
	              // 需要列表id
				  const param = {
						inboundId:this.ruleForm.inboundId?this.ruleForm.inboundId:-1,
						carId:this.ruleForm.carInStorage.carId?this.ruleForm.carInStorage.carId:-1,
				  }
	              this.getCarGpsInfo(param);
	              this.getCarGpsMonitoring(this.ruleForm.carInStorage.carId);
	              this.getCarPrchaseTax(this.ruleForm.carInStorage.carId);
	              // 需要列表id
	              this.getCarInsurance(this.ruleForm.inboundId);
	              this.getCarInspectionNextTime(this.ruleForm.carInStorage.carId);
	          } else {
	            setTimeout(function () {
	              _this.detailInfo();
	            }, 100)
	          }
	        },
  },
};
</script>

<style lang="scss" scoped>
.car-wrap {
  display: flex;
  flex-direction: column;
  padding: 20rpx 20rpx 20rpx 0;
  border: 1px solid #dadada;
  margin: 10rpx 20rpx;
  border-radius: 8rpx;

}


</style>


